package cn.wolfcode.interceptor;


import cn.wolfcode.domain.Employee;
import cn.wolfcode.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//拦截器类
public class LogainInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("被拦截");
        //从作用域中拿取员工对象
        Employee employee = UserContext.getCurrentUser();
        //判断员工对象是否为空
        if (employee==null){
            //为空重定向到登录界面
            response.sendRedirect("/login.html");
            return false;
        }else {
            //不为空放行
            return true;
        }
    }
}
